// GLView.h
/* 
Copyright (c) 2013, Richard S. Wright Jr.
GLTools Open Source Library
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list 
of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list 
of conditions and the following disclaimer in the documentation and/or other 
materials provided with the distribution.

Neither the name of Richard S. Wright Jr. nor the names of other contributors may be used 
to endorse or promote products derived from this software without specific prior 
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef __GLVIEW__
#define __GLVIEW__

#include <gltools.h>
#include <StopWatch.h>
#include <math3d.h>
#include <stdio.h>
#include <GLFrame.h>
#include <GLMatrixStack.h>
#include <GLBatch.h>

#define	BUTTON_A		0x01
#define BUTTON_B		0x02


#define JOY_UP			0x01
#define JOY_DOWN		0x02
#define JOY_LEFT		0x04
#define JOY_RIGHT		0x08



class GLView
	{
	public:
		GLView();
		virtual ~GLView() {};

		void Initialize(void);							// Called after context is created
		void Shutdown(void);							// Called before context is destroyed
		void Resize(GLsizei nWidth, GLsizei nHeight);	// Called when window is resized, at least once when window is created
		void Render(void);								// Called to update OpenGL view
		
		// These methods are used by the calling framework. Set the appropriate internal
		// protected variables to tell the parent framework your desired configuration
		inline GLuint GetWidth(void) { return screenWidth; }
		inline GLuint GetHeight(void) { return screenHeight; }
		inline GLboolean GetFullScreen(void) { return bFullScreen; }
		inline GLboolean GetAnimated(void) { return bAnimated; }
		inline GLuint GetSamples(void) { return samples; }

		inline GLuint GetButtonState(void) { return buttonState; }
		inline void   SetButtonState(GLuint state) { buttonState = state; }
		inline GLuint GetJoyState(void)	   { return joyState; }
		inline void   SetJoyState(GLuint state) { joyState = state; };
		
		void MouseMove();
		void MoveCamera();
		void GetInput();
		void DrawCube(GLfloat x, GLfloat y, GLfloat z);
		void DrawSphere(GLfloat x, GLfloat y, GLfloat z);
		void DrawCube(M3DVector3f position);
		void CreateCube(GLfloat radius);

		void GLView::SetBuffer(size_t bufferSize, void* data, int location, int components);

	protected:

		enum AttributeLocations {ATTRIBUTE_VERTEX, ATTRIBUTE_NORMAL,ATTRIBUTE_TEXTURE0,ATTRIBUTE_TANGENT};
		enum KeyLocations {W,A, S, D, K4,K5,K6,K7,K8,K9,M1,M2,NUMINPUT};
		GLsizei	 screenWidth;			// Desired window or desktop width
		GLsizei  screenHeight;			// Desired window or desktop height
		
		GLboolean bFullScreen;			// Request to run full screen
		GLboolean bAnimated;			// Request for continual updates
		GLboolean bGameMode;			// Request a game device mode

		GLuint    samples;

		GLuint		buttonState;
		GLuint		joyState;

		M3DMatrix44f projMatrix;
		M3DVector4f  lightPos;

		GLfloat moveSpeed;
		GLfloat turnSpeed;

		GLMatrixStack modelViewMatrix;
		CStopWatch stopwatch;
		CStopWatch rotationWatch;

		unsigned short keymap;
		unsigned short pressedmap;

		GLFrame camera;


		GLuint cubeVAO;
		GLuint	hCustomCubeShader;
		GLint	hUniMVPCCS;
		GLint	hUniModelViewCCS;
		GLint	hUniNormalMatrixCCS;
		GLint	hUniLightPosCCS;
		GLint	hUniNormalToggleCCS;
		GLint   samplerCCS;

		GLuint	hShader;
		GLint	hUniMVP;
		GLint	hUniModelView;
		GLint	hUniNormalMatrix;
		GLint	hUniLightPos;
		GLint	hUniNormalToggle;
		GLTriangleBatch sphere;
		GLBatch cube;

		GLuint brickTexture;
		GLuint brickNormal;
		GLint sampler;
		GLuint planetTexture;
		GLuint planetNormal;

		bool bNormalToggle;



	};
		
#endif // __GLVIEW__
